package com.nondo.rdp.finance.domain.course;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.nondo.rdp.core.domain.base.BaseEntity;
import com.nondo.rdp.finance.config.DbConfig;

/**
 * 求知-课程分类
 */
@Entity
@Table(name = DbConfig.DEFAULT_TABLE_PREFIX + "courseClassify", indexes = {@Index(columnList = "pid")})
public class CourseClassify extends BaseEntity {
	
	private static final long serialVersionUID = 7767453040290264818L;
	
	private Long id;// 主键
    private String name;// 父分类名称
    private Long pid; // 父分类ID
    private Integer type; // 0=专辑|普通=1
    private int sort = 0;// 排序

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Length(min = 2, max = 10, message = "分类名称长度不能小于2且不能超过10个字符")
    @Column(name = "name", length = 10, unique = true)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @JsonIgnore
    @Column(columnDefinition = "int default 0", nullable = false)
	public Long getPid() {
		return pid;
	}

    @JsonSetter
	public void setPid(Long pid) {
		this.pid = pid;
	}

	@JsonIgnore
	@NotNull(message = "分类类型不能为空")
	@Column(columnDefinition = "int default 0", nullable = false)
	public Integer getType() {
		return type;
	}

	@JsonSetter
	public void setType(Integer type) {
		this.type = type;
	}

	@Column(columnDefinition = "int default 0", nullable = false)
	public int getSort() {
		return sort;
	}

	public void setSort(int sort) {
		this.sort = sort;
	}
}
